<?php
namespace control;
/*
*绩效评分类
*/

class performanceScoreClass extends adIndexClass
{
    private const page = 'performanceScore';
    private const table = 'performance_score';
    private const tableMx = 'performance_score_detail';
    private const title = '绩效评分';
    public array $stateOption = ['草稿', '审核中', '已通过'];

    /**
     * 员工页卡绩效记录
     *
     * @return bool|string
     */
    public function achievements(): bool|string
    {
        $html =
            hidden(array("name" => "targetId", "value" => $this->get('id'))) .
            select(array("name" => "team", "title" => L('performance.table.team'), "option" => explode('，', para('performanceTeam')))) .
            text(array("name" => "createTime", 'class' => 'width200', 'laydate' => ['type' => 'month', 'range' => '~'], "title" => L('performance.table.month') . "-" . L('performance.table.month')));
        //返回
        $json['html'] = $this->search($html);
        return json_encode($json, 320);
    }

    public function achievementsSearch(): bool|string
    {
        $id = $this->post('targetId');
        $and = " and member like '%$id%'";
        $like = [];
        //全等查询数组
        $equal = array(
            "team" => $this->post('team'),//绩效组
            "state" => '已通过',//状态
        );
        if ($this->post('createTime')) {
            $timeArr = explode('~', $this->post('createTime'));
            $and .= " and month >='{$timeArr[0]}' and month <='{$timeArr[1]}'";
        }
        //获取查询结果
        $where = search(array("like" => $like, "=" => $equal)) . $and;
        $page = $this->page(array("table" => self::table, "where" => $where, "order" => "month desc"));
        //获取表头
        $tr[] = array('', L('performance.table.month'), L('performance.table.team'), L('performance.table.scoringMember'), L('performance.table.actualScore'), L('department.table.creator'), L('department.table.creatTime'), L('recruitment.table.state'));
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "detail" => array("title" => L('performance.table.scoreInfo'), "click" => "newIframe('" . L('performance.table.scoreInfo') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
            );
            $score = find(array('table' => self::tableMx, 'where' => " orderId = '$array[id]'", 'sum' => 'score'));
            $tr[] = array($this->dominate($dominate), $array['month'], $array['team'], $this->findMember($array['member'], 2), $score, self::findStaff($array['stid']), $array['time'], $array['state']);
        }
        //返回
        $json['html'] = $page['hint'] . "<form name='trainRecordForm'>" . space . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'] . clear;
        return json_encode($json, 320);
    }

    /*列表-查询条件*/
    public function home()
    {
        //生成查询表单
        $html =
            text(array("name" => "member", "title" => L('performance.table.scoringMember'))) .
            select(array("name" => "team", "title" => L('performance.table.team'), "option" => explode('，', para('performanceTeam')))) .
            select(array("name" => "state", "title" => L('recruitment.table.state'), "option" => $this->stateOption)) .
            text(array("name" => "createTime", 'laydate' => ['type' => 'month', 'range' => '~'], "title" => L('performance.table.month') . "-" . L('performance.table.month')));
        //返回
        return $this->homeFun($this->search($html));
    }

    /*客户列表-查询结果*/
    public function homeSearch()
    {
        //like查询数组
        $like = [];
        //全等查询数组
        $equal = array(
            "team" => $this->post('team'),//绩效组
            "state" => $this->post('state'),//状态
        );
        $and = $this->seeSelf(self::page);
        if ($this->post('createTime')) {
            $timeArr = explode('~', $this->post('createTime'));
            $and .= " and month >='{$timeArr[0]}' and month <='{$timeArr[1]}'";
        }

        //获取查询结果
        $where = search(array("like" => $like, "=" => $equal)) . $and;
        $page = $this->page(array("table" => self::table, "where" => $where, "order" => "month desc"));
        //获取表头
        $checkAll = $this->checkAll("listForm", "listId");
        $tr[] = array($checkAll, L('performance.table.month'), L('performance.table.team'), L('performance.table.scoringMember'), L('performance.table.actualScore'), L('department.table.creator'), L('department.table.creatTime'), L('recruitment.table.state'));
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box" => array("name" => "listId", "value" => $array['id']),
                "detail" => array("title" => L('performance.table.scoreInfo'), "click" => "newIframe('" . L('performance.table.scoreInfo') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
            );
            $score = find(array('table' => self::tableMx, 'where' => " orderId = '$array[id]'", 'sum' => 'score'));
            $tr[] = array($this->dominate($dominate), $array['month'], $array['team'], $this->findMember($array['member'], 2), $score, self::findStaff($array['stid']), $array['time'], $array['state']);
        }
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"newIframe('" . L('performance.table.scoreInfo') . "','" . $url . "&fun=edit')\" class='spanButton'>" . L('job.model.edit') . "</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'del'})\">" . L('job.button.delete') . "</span>\n";
        }
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . space . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'] . clear;
        return json_encode($json, 320);
    }

    /**
     * 获取参训人员姓名
     */
    public function findMember($member, $style = 1): string
    {
        $result = '';
        if ($member) {
            $memberArr = explode(',', $member);
            foreach ($memberArr as $stid) {
                $name = self::findStaff($stid);
                if ($style == 1) {
                    $result .= "<span class='background-color-gray'>{$name}</span>";
                } else {
                    $result .= ',' . $name;
                }
            }
        }
        if ($style !== 1 && $result) {
            $result = ltrim($result, ',');
        }
        return $result;
    }

    /**
     * 编辑页
     * @return string
     */
    public function edit(): string
    {
        $id = $this->get('id') ?: suiji();
        $info = query(self::table, " id = '" . $id . "' ");
	    $button[]  = [
		    "name"  => L('public.save'),
		    "type"  => "点击事件",
		    "cla"   => $this->get('cla'),
		    "fun"   => "subForm('" . self::page . "EditForm', root+'control/adIndex.html?cla=" . self::page . "&fun=editEdit')",
		    "post"  => ["id" => $this->get('id')],
		    'style' => 'li-btn-blue-bg',
	    ];
	    $button[]  = [
		    "name"  => L('public.saveDraft'),
		    "type"  => "点击事件",
		    "cla"   => $this->get('cla'),
		    "fun"   => "saveTemp('" . self::page . "', 'edit', '" . self::page . "EditForm')",
		    "post"  => ["id" => $this->get('id')],
		    'style' => 'li-btn-green-bg',
	    ];
		
        //表单
        $data['html'] = $this->layerEdit([
            "table" => [
	            [
		            $this->tableShowButton($button)
	            ],
                [
                    must . L('performance.table.month') . "：" => text(array('name' => 'month', 'laydate' => ['type' => 'month'], 'class' => 'text', 'value' => $info['month'] ?: date('Y-m'))),
                ],
                [
                    must . L('performance.table.team') . "：" => select(array('name' => 'team', 'title' => L('performance.table.team'), 'class' => 'select', 'value' => $info['team'], 'option' => explode('，', para('performanceTeam')))),
                ],
                [
                    must . L('performance.table.scoringMember') . "：" => componentClass::staffSelector($info['selector'])
                ],
                [
                    L('performance.table.text') . "：" => textarea(array('name' => 'text', 'class' => 'textarea', 'value' => $info['text'])),
                ],
            ],
            'hidden' => hidden(array('name' => 'id', 'value' => $info['id'] ?: $id)),
            'button' => ' ',
        ]);
        //返回
        return $this->tab($data);
    }

    public function editEdit()
    {
        $id = $this->post('id') ?: self::getId();
        $field = [
            'team' => $this->post('team'),
            'month' => $this->post('month'),
            'selector' => $this->post('staff')[0] ?? '',//员工选择器
            'text' => $this->post('text'),
        ];
        $staff = componentClass::returnStaffId($field['selector']);
        $field['member'] = implode(',', $staff);
        $annotation = [
            'team' => L('performance.table.team'),
            'month' => L('performance.table.month'),
            'member' => L('performance.table.scoringMember'),
        ];
        $rules = [
            'team' => 'required',
            'month' => 'required',
            'member' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = L('performance.table.score_edit_permission');
        } else {
            $json['warn'] = '';
            if (is_array($staff)) {
                foreach ($staff as $stid) {
                    if (static::total(array('table' => self::table, 'where' => "member like '%$stid%' and month = '$field[month]' and id !='$id'")) > 0) {
                        $json['warn'] = str_replace(['{{name}}'], [self::findStaff($stid)], L('performance.table.exist_staff'));
                    }
                }
            }
            if (empty($json['warn'])) {
                $where = " id = '$id' ";
                $info = query(self::table, $where);
                if (!$info['id']) {
                    $userNo = codeTemplateClass::generateCode(self::page, [
                        'prefix' => 'PS',
                        'table' => self::table,
                        'field' => 'orderNo',
                        'where' => '',
                    ], $field);
                    $field = array_merge($field, [
                        'id' => $id,
                        'orderNo' => $userNo,
                        'stid' => $this->control['stid'],
                        'state' => '草稿',
                        'time' => $this->time
                    ]);
                    $json['warn'] = static::insert(["table" => self::table, "field" => $field]);
                } else {
                    $json['warn'] = static::update([
                        "table" => self::table,
                        "field" => $field,
                        "where" => $where
                    ]);
                }
                if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                    //添加日志
                    $text = str_replace(['{{staffName}}', '{{month}}', '{{team}}', '{{id}}'], [$this->control['name'], $field['month'], $field['team'], $id], L('performance.table.score_edit_text'));
                    $this->logText(["type" => self::page, "text" => $text]);
                    //返回
                    $_SESSION['warn'] = $json['warn'];
                    $json['warn'] = 2;
                    $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&id=" . $id;
                }
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /**
     * 审核按钮
     * @param $info
     * @return array
     */
    public function auditButton($info): array
    {
        $button = [];
        if ($info['state'] == '草稿' || auditClass::auditFlag(self::table, $info['id'], 'selfChoose')) {
            $button[] = [
                "name" => L('recruitment.table.commitAudit'),
                "type" => "弹出层",
                "cla" => 'audit',
                "fun" => "operate",
                'style' => 'li-btn-blue-bg',
                "post" => ["act" => 'start', "id" => $info['id'], 'body' => self::encryptDecrypt(json_encode([
                    'name' => '绩效评分',
                    'table' => self::table,
                    'process' => [
                        // 预览函数
                        'detail' => [
                            'cla' => $this->get('cla'),
                            'fun' => 'detail'
                        ],
                        // 保存函数
                        'save' => [
                            'cla' => $this->get('cla'),
                            'fun' => 'editEdit'
                        ],
                        //执行发起时验证函数
                        'before' => [
                            'cla' => $this->get('cla'),
                            'fun' => ''
                        ],
                        //完成发起后执行函数
                        'after' => [
                            'cla' => $this->get('cla'),
                            'fun' => ''
                        ],
                    ],
                ], 320))],
            ];
        }
// 审批并判断是否有权限
        if ($info['state'] == '审核中' && auditClass::auditFlag(self::table, $info['id'])) {
            $button[] = [
                "name" => L('recruitment.table.audit'),
                "type" => "弹出层",
                "cla" => 'audit',
                "fun" => "operate",
                // 以下参数固定格式
                "post" => ["act" => 'approval', "id" => $info['id'], 'body' => self::encryptDecrypt(json_encode([
                    'table' => self::table,
                    // 当前状态
                    'state' => $info['state'],
                    // 变更
                    'field' => ['state'],   //变更字段 可多个
                    'value' => [
                        'state' => ['草稿', '已通过'],
                    ],
                    // 审核时回调
                    'process' => [
                        //执行首次审核时验证
                        'before' => [
                            'cla' => $this->get('cla'),
                            'fun' => ''
                        ],
                        //执行末次审核后处理
                        'after' => [
                            'cla' => $this->get('cla'),
                            'fun' => ''
                        ],
                    ],
                ], 320))],
                'style' => 'li-btn-blue-bg',
            ];
            $button[] = [
                "name" => L('recruitment.table.addAudit'),
                "type" => "弹出层",
                "cla" => 'audit',
                "fun" => "operate",
                "post" => ["act" => 'addApprover', "id" => $info['id'], 'body' => self::encryptDecrypt(json_encode([
                    'table' => self::table
                ], 320))],
            ];
            $button[] = [
                "name" => L('recruitment.table.transmit'),
                "type" => "弹出层",
                "cla" => 'audit',
                "fun" => "operate",
                "post" => ["act" => 'transfer', "id" => $info['id'], 'body' => self::encryptDecrypt(json_encode([
                    'table' => self::table
                ], 320))],
            ];

        }

        // 撤销审批
        if (auditClass::auditFlag(self::table, $info['id'], 'cancel') && $info['state'] != '草稿') {
            $button[] = [
                "name" => L('recruitment.table.cancel'),
                "type" => "弹出层",
                "cla" => 'audit',
                "fun" => "operate",
                "post" => ["act" => 'cancel', "id" => $info['id'], 'body' => self::encryptDecrypt(json_encode([
                    'table' => self::table,
                    // 当前状态
                    'state' => $info['state'],
                    // 变更
                    'field' => ['state'],   //变更字段 可多个
                    'value' => [
                        'state' => ['草稿'],
                    ],
                    'process' => [
                        //完成发起后执行函数
                        'after' => [
                            'cla' => $this->get('cla'),
                            'fun' => ''
                        ],
                    ],
                ], 320))],
            ];
        }
        return $button;
    }

    /*详情页*/
    public function detail(): string
    {
        $info = query(self::table, " id = '{$this->get('id')}'");
        if (empty($info['id'])) {
            $html = L('performance.table.score_none');
        } else {
            //菜单
            $data = array(
                "id" => $info['id'],
            );
            $mxButton = '';//招聘目标按钮
            $button = [];
            if ($this->power(self::page, "edit") && $info['state'] == '草稿') {
                //按钮
                $button[] = [
                    "name" => L('department.button.editor'),
                    "type" => "顶部页卡",
                    "title" => L('department.button.editor'),
                    "url" => $this->root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=edit&id=' . $info['id'],
                ];
                $mxButton = "<span class='spanButton spanButton-other' onclick=\"layer('" . self::page . "','addMx',{id:'" . $info['id'] . "'})\">选择绩效目标</span><span class='spanButton' onclick=\"layer('" . self::page . "','operate',{id:'" . $info['id'] . "',act:'delMx'})\">删除</span>";
            }
            if ($this->power(self::page, "del") && $info['state'] == '草稿') {
                //按钮
                $button[] = [
                    "name" => L('department.button.delete'),
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "operate",
                    "post" => ["act" => 'del', "id" => $info['id']],
                ];
            }

            //审核按钮
            $button = array_merge($button, $this->auditButton($info));

            $result = find(array('table' => self::tableMx, 'where' => "orderId = '$info[id]' order by list asc"));
            $checkAll = $this->checkAll("detailForm", "mxId");
            $tr[] = [$checkAll, L('performance.table.team'), L('performance.table.aimType'), L('performance.table.evaluation'), L('performance.table.rule'), L('performance.table.basis'), L('performance.table.scroe'), L('performance.table.factScore')];
            foreach ($result['array'] as $val) {
                //列表控件
                $dominate = array(
                    "box" => array("name" => "mxId", "value" => $val['id']),
                );
                $performanceAim = query('performance_aim', " id = '$val[sourceId]'");
                $tr[] = [$this->dominate($dominate), $performanceAim['team'], $performanceAim['aimType'], $performanceAim['evaluation'], $performanceAim['rule'], $performanceAim['basis'], $performanceAim['score'], text(array('name' => 'score[]', 'class' => 'text', 'other' => "data-id='{$val['id']}'", 'blur' => 'setText', 'value' => $val['score']))];
            }

            //生成表单
            $data['html'] = $this->tableShow(array(
                "button" => $button,
                array(
                    array(
                        L('performance.table.scoreOrderNo') => $info['orderNo'],
                        L('performance.table.month') => $info['month'],
                        L('performance.table.team') => $info['team'],
                    ),
                    array(
                        L('performance.table.scoringMember') => componentClass::showSelector($info['selector']),
                    ),
                    array(
                        L('department.table.creator') => self::findStaff($info['stid']),
                        L('department.table.creatTime') => $info['time'],
                        L('recruitment.table.state') => $info['state'],
                    ),
                    array(
                        L('performance.table.text') => $info['text'],
                    ),
                ),
                L('performance.table.details') => array(
                    array(
                        "<div>{$mxButton}</div>
                         <div class='purchaseMx' style='margin-top: 5px'><form name='detailForm'>" . hidden(array('name' => 'id', 'value' => $info['id'])) . $this->tableMany(array('tr' => $tr)) . "</form></div>"
                    ),
                ),
                L('recruitment.table.flow') => array(
                    array(
                        auditClass::auditRecord(self::table, $info['id'])
                    )
                ),
            ));
            $data['html'] .= <<<eof
<style>
 .spanButton-other{
    width: auto;
    padding: 0 10px;
    margin-left: 0
 }
</style>
<script>
         function setText (obj){
         let id = $(obj).data('id');
            let val = $(obj).val()
            $.post(root+'control/adIndex.html?cla={$this->get('cla')}&fun=setScore',{id:id, text:val},function(res) {
                if(res.warn !== 1){
                   warn(res.warn)
                }
            },'json')
    }
</script>
eof;
            //生成页面
            $html = $this->tab($data);
        }
        //返回
        return $html;
    }

    /**
     * 填写实际得分
     * @return bool|string
     */
    public function setScore()
    {
        $id = $this->post('id');
        $infoMx = query(self::tableMx, " id = '$id' ");
        $info = query(self::table, " id = '{$infoMx['orderId']}' ");
        if (!$infoMx['id']) {
            $json['warn'] = L('performance.table.details_none');
        } elseif ($info['state'] != '草稿') {
            $json['warn'] = L('performance.table.score_draft');
        } else {
            $json['warn'] = update([
                'table' => self::tableMx,
                'field' => [
                    'score' => $this->post('text'),
                    'updateTime' => $this->time,
                ],
                'where' => " id = '$id' "
            ]);
            if ($json['warn'] == '更新成功') {
                $json['warn'] = 1;
            }
        }
        return json_encode($json, 320);
    }

    /**
     *
     * @return bool|string
     */
    public function addMx()
    {
        $html =
            text(array("name" => "team", "title" => L('performance.table.team'))) .
            text(array("name" => "aimType", "title" => L('performance.table.aimType'))) .
            text(array("name" => "evaluation", "title" => L('performance.table.evaluation'))) .
            hidden(array('name' => 'id', 'value' => $this->post('id')));
        $button = "<input style='margin-left: 5px' onclick=\"subForm('mxForm', '" . root . "control/adIndex.html?cla=" . self::page . "&fun=addMxEdit');\" type='button' class='searchSub' value='" . L('recruitment.table.commit') . "'>";
        $html = "<div style='padding: 10px'>" . $this->search($html, null, $button) . "</div>";
        return $this->layer(array("title" => L('recruitment.table.addMx'), "height" => 600, "width" => 1100, "html" => $html));
    }

    /**
     *添加招聘目标
     */
    public function addMxSearch()
    {
        $id = $this->post('id');
        $where = " 1=1 and id not in (select sourceId from " . self::tableMx . " where sourceTable = 'performance_aim ' and orderId = '$id')";
        $and = '';
        $like = [
            'aimType' => $this->post('aimType'),
            'evaluation' => $this->post('evaluation'),
            'team' => $this->post('team'),
        ];
        $equal = [
            'state' => '启用',
        ];
        $where .= search(["like" => $like, "=" => $equal]) . $and;
        $page = $this->page([
            "table" => "performance_aim",
            "where" => $where,
            'pageNum' => 50,
            "order" => " `time` ASC",
        ]);
        //获取表头
        $checkAll = $this->checkAll("mxForm", "mxId");
        $tr[] = [$checkAll, L('performance.table.team'), L('performance.table.aimType'), L('performance.table.evaluation')];
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate = array(
                "box" => array("name" => "mxId", "value" => $array['id']),
            );
            $tr[] = array(
                $this->dominate($dominate),
                $array['team'],
                $array['aimType'],
                $array['evaluation'],
            );
        }
        $json['html'] = $page['hint'] . "<form name='mxForm'>" . space . hidden(array('name' => 'id', 'value' => $id)) . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 编辑
     * 添加
     * @return bool|string
     */
    public function addMxEdit()
    {
        $id = $this->post('id');
        $mxIdArr = $this->post('mxId');
        $info = query(self::table, " id = '{$this->post('id')}'");
        if (!$this->power(self::page, 'edit')) {
            $json['warn'] = L('performance.table.score_edit_permission');
        } elseif (empty($mxIdArr) || !is_array($mxIdArr)) {
            $json['warn'] = L('performance.table.chooseScore');
        } else {
            $x = 0;
            foreach ($mxIdArr as $mxId) {
                $performanceAim = query('performance_aim', " id = '$mxId'");
                $mx = query(self::tableMx, " sourceId = '$mxId' and orderId = '$id'");
                if (!$mx['id']) {
                    //未在明细中
                    $warn = insert(array(
                        'table' => self::tableMx,
                        'field' => [
                            'id' => suiji(),
                            'orderId' => $id,
                            'sourceTable' => 'performance_aim',
                            'sourceId' => $mxId,
                            'time' => $this->time
                        ]
                    ));
                    if ($warn == '新增成功') {
                        $x++;
                        $text = str_replace(['{{staffName}}', '{{aim}}', '{{orderNo}}'], [$this->control['name'], $performanceAim['orderNo'], $info['orderNo']], L('performance.table.addMx_edit'));
                        $this->logText(array("type" => self::page, "text" => $text));
                    }
                }
            }
            $json['warn'] = 2;
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('performance.table.addMx_warn'));
        }
        return json_encode($json, 320);
    }


    // 操作中转
    public function operate()
    {
        $act = $this->post('act') ?? '';
        $pwd = false; // 需要密码
        $form = $power = '';
        switch ($act) {
            case 'delMx':
                $act = 'del';
                $msg = L('performance.table.del_detail');
                $title = self::table . 'DeleteMx';
                $function = 'deleteMx';
                $form = self::page . 'OperateForm, detailForm';
                $power = '';
                break;
            default:
                $act = 'del';
                $msg = L('performance.table.del_score');
                $title = self::page . 'Delete';
                $function = 'delete';
                $form = self::page . 'OperateForm, listForm';
                $power = '';
                break;
        }
        if (!$this->power(self::page, $act)) {
            $_SESSION['warn'] = str_replace(['{{msg}}'], [$msg], L('jon.other.permission_warn'));
            $json = [
                'warn' => 2,
                'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
            ];
        } else {
            return $this->confirm([
                'title' => $title,
                'function' => $function,
                'form' => $form,
                'power' => $power,
                'pwd' => $pwd,
            ]);
        }

        resp:
        return json_encode($json, 320);
    }

    /**
     * 删除绩效明细
     * @return bool|string
     */
    public function deleteMx()
    {
        $array = $this->post('mxId');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = L('staffProfiles.tip.permission_del_warn');
        } elseif (empty($array)) {
            $json['warn'] = L('staffProfiles.tip.no_data_choose');
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $mx = query(self::tableMx, " id = '$id' ");
                $performanceAim = query('performance_aim', " id = '$mx[sourceId]' ");
                //最后删除基本参数
                delete(array("table" => self::tableMx, "where" => " id = '$id' "));
                //返回
                $warn = L('job.other.delete_success');
                $x++;
                $text .= str_replace(['{{orderNo}}', '{{id}}'], [$performanceAim['orderNo'], $mx['id']], L('performance.table.mx_del_text')) . $warn . "。<br>";
            }
            //添加日志
            $text = str_replace(['{{staffName}}'], [$this->control['name']], L('performance.table.mx_del_log')) . "<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('performance.table.mx_del_warn'));
            $json['warn'] = 2;
        }
        return json_encode($json, 320);
    }

    /**
     * 删除
     * @return bool|string
     */
    public function delete()
    {
        $array = $this->post('listId') ?? $this->post('id');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = L('staffProfiles.tip.permission_del_warn');
        } elseif (empty($array)) {
            $json['warn'] = L('staffProfiles.tip.no_data_choose');
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $info = query(self::table, " id = '$id' ");
                if ($info['state'] != '草稿') {
                    $warn = L('recruitment.table.draft');
                } else {
                    //删除待办事项
                    delete(array("table" => "backlog", "where" => " typeId = '$id' "));
                    delete(array("table" => self::tableMx, "where" => " orderId = '$id' "));
                    //最后删除基本参数
                    delete(array("table" => self::table, "where" => " id = '$id' "));
                    //返回
                    $warn = L('recruitment.table.del_suc');
                    $x++;
                }
                $text .= str_replace(['{{team}}', '{{month}}', '{{id}}'], [$info['team'], $info['month'], $info['id']], L('performance.table.del_text')) . $warn . "。<br>";

            }
            //添加日志

            $text = str_replace(['{{staffName}}'], [$this->control['name']], L('performance.table.del_log')) . "<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('performance.table.del_warn'));
            $json['warn'] = 2;
            $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=home";
        }
        return json_encode($json, 320);
    }

}

